<?php
/**
 * Created by PhpStorm.
 * User: code001
 * Date: 20-6-19
 * Time: 下午2:31
 */
namespace App\Admin\Actions;

use App\Lib\Sdk\Manager;
use App\Models\Robots;
use Encore\Admin\Admin;
use Illuminate\Contracts\Support\Renderable;


class RobotLoginRenderable implements Renderable
{
    public function render($key = null)
    {
        $robot = Robots::where("id", $key)->first();
        $manager = Manager::getSdk();
        $data = $manager->loginQr($robot);

        return "
              <div class = 'row'>
                 <div class='col-md-6'>
                        <img width='400px' src='".$data."'/> 
                  </div>
                    <div class='col-md-6' style='line-height: 200px'>
                    已经在手机微信端确认登录？请点击
                    <button class='btn btn-success' onclick='javascript:window.location.reload()'>刷新</button>
                    </div>
            </div>
            <script>
            var show=window.setInterval(myFunction, 1000 * 5);
            
            function myFunction() {
                $.getJSON(\"/admin/robots/checklogin?uid=\" + $robot->user_id, function(res) {
                    if (res.status == 1) {
                    clearInterval(show);
                    //alert('成功');
                      $('.grid-modal').hide();
                      $('.modal-backdrop').hide();
                      location.reload();
                    }
                });
            }
            </script>
        ";
    }


}